<template>
	<view>
		<view>
			<view style="margin-top: 180rpx">
        <!-- #ifdef MP-WEIXIN -->
        <view style="display: flex;flex-direction: column;align-items: center;">
          <view style="width: 150rpx;height: 150rpx;margin-top: 30rpx">
            <open-data   type="userAvatarUrl"></open-data>
          </view>
          <view style="width: 150rpx;height: 150rpx;margin-top: 30rpx">
            <open-data type="userNickName"></open-data>
          </view>
        </view>
        <!-- #endif -->
        <!-- #ifdef MP-ALIPAY -->
        <view style="display: flex;flex-direction: column;align-items: center;">
          <view style="width: 150rpx;height: 150rpx;margin-top: 30rpx">
            <image style="width: 150rpx;height: 150rpx;" src="@/static/logo.png"></image>
          </view>
          <view style="width: 150rpx;height: 150rpx;margin-top: 30rpx;display: flex;justify-content: center">
            <text>云助手</text>
          </view>
        </view>
        <!-- #endif -->
        <view class="content">
					<view>申请获取以下权限</view>
					<text>获取你的手机号(注册并登录申请成为会员)</text>
				</view>
            <button class="bottom" type="primary" open-type="getPhoneNumber" @getphonenumber="getphonenumber" >注册并登录</button>
      </view>
		</view>
	</view>
</template>
<script>
import {mapState} from 'vuex';
	import {
		getTokenByCode,
    register
	} from "@/api/user.js"
	export default {
		data() {
			return {
				uid: 0,
				SessionKey: '',
				OpenId: '',
				encryptedData: null,
				iv: null,
				spread: null,
				isCanUse: uni.getStorageSync('isCanUse') || true, //默认为true
				code: null,
				// token: ''
			};
		},
    computed: {
      ...mapState({
        userInfo: state => state.user.userInfo,
        token: state => state.user.token,
        mchId: state => state.user.mchId,
        uuid: state => state.user.uuid,
        userId: state => state.user.userId
      })
    },
		methods: {
      getphonenumber(e){
        console.log(e)
        console.log(e,"eeeeeeeeeeee")
        var e = e
        var that = this
        // #ifdef MP-WEIXIN
        uni.login({
          provider: 'weixin',
          success: res => {
            var weixinres = res
            console.log(res, "codecodecodecodecode")
            getTokenByCode({
              mchId: that.mchId,
              auth_code: res.code,
              uuid: that.uuid,
              pluginId: 'weixinMiniAuthPlugin'
            }).then(
                res => {
                  console.log(res)
                  if (res.type == 'success') {
                    res.data.token = null
                    if(res.data.token == null){
                      console.log(weixinres,"weixinresweixinresweixinres")
                      this.$store.commit('callRegister',e);
                    }
                  } else {
                    wx.showToast({
                      icon: "none",
                      title: res.content
                    })
                  }
                }
            ).catch(error => {
              console.log(error,"321321")
            })
          }
        })
        // #endif
        // #ifdef MP-ALIPAY
        uni.login({
          provider: 'alipay',
          success: res => {
            var weixinres = res
            console.log(res, "codecodecodecodecode")
            getTokenByCode({
              mchId: that.mchId,
              auth_code: res.code,
              uuid: that.uuid,
              pluginId: 'alipayMiniAuthPlugin'
            }).then(
                res => {
                  console.log(res)
                  if (res.type == 'success') {
                    res.data.token = null
                    if(res.data.token == null){
                      console.log(weixinres,"weixinresweixinresweixinres")
                      this.$store.commit('callRegister',e);
                    }
                  } else {
                    wx.showToast({
                      icon: "none",
                      title: res.content
                    })
                  }
                }
            ).catch(error => {
              console.log(error,"321321")
            })
          }
        })
        // #endif
      },
		},
		onUnload() {},
		onLoad() {
		}
	};
</script>
<style lang="less">
	.header {
		margin: 90rpx 0 90rpx 50rpx;
		border-bottom: 1px solid #ccc;
		text-align: center;
		width: 650rpx;
		height: 300rpx;
		line-height: 450rpx;
	}

	.header image {
		width: 200rpx;
		height: 200rpx;
	}

	.content {
		margin-left: 50rpx;
		margin-bottom: 90rpx;
	}

	.content text {
		display: block;
		color: #9d9d9d;
		margin-top: 40rpx;
	}

	.bottom {
		border-radius: 80rpx;
		margin: 70rpx 50rpx;
		font-size: 35rpx;
	}
</style>
